package com.hycat.mail.product.service.impl;

import com.hycat.mail.product.service.CategoryBrandRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hycat.mail.common.utils.PageUtil;
import com.hycat.mail.common.utils.Query;
import com.hycat.mail.product.dao.BrandDao;
import com.hycat.mail.product.entity.BrandEntity;
import com.hycat.mail.product.service.BrandService;
import org.springframework.util.StringUtils;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                new QueryWrapper<BrandEntity>()
        );

        return new PageUtil(page);
    }

    @Override
    public void updateDetails(BrandEntity brand) {
        this.updateById(brand);
        //对品牌分类关联表进行修改
        if(!StringUtils.isEmpty(brand)) {
            categoryBrandRelationService.updateDetails(brand.getBrandId(), brand.getName(), "brand");
        }
    }

}